<template>
  <div>
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card shadow="never">
            <div class="card-title">总关注人数</div>
            <div class="card-number">{{ total }}</div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card shadow="never">
            <div class="card-title">近一个月新增人数</div>
            <div class="card-number">{{ new_current_month }}</div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <div style="height: 15px;" />
    <div>
      <el-card shadow="never">
        <el-form :inline="true" @submit.native.prevent>
          <el-form-item label="昵称">
            <el-input v-model="search" placeholder="请输入昵称" @keyup.enter.native="handleSearch" />
          </el-form-item>
          <el-form-item label="学校">
            <HighSchoolSelect v-model="school" />
          </el-form-item>
          <el-form-item label="地区">
            <AreaSelect v-model="area" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <div style="height: 15px;" />
    <div>
      <el-table v-loading="table.loading" :data="table.data" border>
        <el-table-column prop="name" label="昵称" />
        <el-table-column prop="mobile" label="手机号" />
        <!--        <el-table-column prop="avatar" label="头像">-->
        <!--          <template slot-scope="t">-->
        <!--            <el-image-->
        <!--              style="width: 80px; height: 80px"-->
        <!--              :src="t.row.avatar"-->
        <!--              fit="cover"-->
        <!--            >-->
        <!--              <div slot="error">-->
        <!--                <img src="@/assets/fail_image/default.png" class="slot-avatar">-->
        <!--              </div>-->
        <!--            </el-image>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column prop="sex_readable" label="性别" />
        <el-table-column prop="user_type_readable" label="类型" />
        <el-table-column prop="area" label="位置" />
        <el-table-column prop="school" label="学校" />
        <el-table-column prop="grade" label="年级" />
      </el-table>
    </div>
    <WrapPagination>
      <el-pagination
        class="pagination"
        :current-page="table.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="table.size"
        layout="prev, pager, next"
        :total="table.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </WrapPagination>
  </div>
</template>

<script>
import { TableMixin } from '../components/mixin'
import { getList, getStatistics } from '../api/follower'

export default {
  components: {
    HighSchoolSelect: () => import('../components/HighSchoolSelect'),
    AreaSelect: () => import('../components/AreaSelect')
  },
  mixins: [TableMixin],
  data() {
    return {
      search: '',
      school: '',
      area: [],
      total: 0,
      new_current_month: 0
    }
  },
  mounted() {
    this.getList()
    this.getStatistics()
  },
  methods: {
    getStatistics() {
      getStatistics().then(res => {
        this.total = res.total
        this.new_current_month = res.new_current_month
      })
    },
    getList() {
      this.wrapResourceList(getList, {
        search: this.search,
        area: this.area,
        school: this.school
      })
    },
    handleSearch() {
      this.getList()
    }
  }
}
</script>

<style>
  .card-title {
    font-size: 18px;
    margin-bottom: 5px;
  }
</style>
<style scoped>
  .slot-avatar {
    width: 80px;
    height: 80px;
  }
</style>
